package cn.edu.ctbu.lablist.controller;

import cn.edu.ctbu.lablist.domain.Student;
import cn.edu.ctbu.lablist.domain.Teacher;
import cn.edu.ctbu.lablist.service.StudentService;
import cn.edu.ctbu.lablist.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
public class TeacherController {


    @Autowired
    TeacherService teacherService;

    @RequestMapping("/teacher/tlist")
    public String list(HttpServletRequest httprequest, Model model){

        HttpSession session = httprequest.getSession();
        if(session.getAttribute("userid")==null){
            //没有登陆，需要登陆
            return "redirect:/login/user";
        }

        List<Teacher> teachers = teacherService.findAll();
        model.addAttribute("data",teachers);


        return "/teacher/tlist";
    }
}
